package edu.cmu.ibill.controller;

import javax.servlet.http.HttpServletRequest;

import edu.cmu.ibill.databeans.User;
import edu.cmu.ibill.model.*;

public class AddSharedUserAction extends Action {

	UserDAO userDAO;

	public AddSharedUserAction(Model model) {
		this.userDAO = model.getUserDAO();
	}

	@Override
	public String getName() {
		return "addshareduser.do";
	}

	@Override
	public String perform(HttpServletRequest request) {

		String email = request.getParameter("email");

		User user = userDAO.Lookup(email);

		if (user == null)
			return "#data#-1;";
		else {
			StringBuilder sb = new StringBuilder();
			sb.append("#data#").append(user.getId()).append(";").append(user.getFirstname());
			return sb.toString();
		}
	}

}
